通过微软自带的System.net.mail通过SMTP来实现邮件自动发送,遇到问题私信https://blog.csdn.net/m0_38093650
string MailFrom = "发送方邮件@126.com";
string SmtpType = "smtp.126.com";
string SmtpPassword = "发送方SMTP密码";
MailAddress from = new MailAddress(MailFrom);
MailMessage mailMessage = new MailMessage();
ConvertMailAddress(mailMessage.To, toAddress);//接收方邮件地址集
ConvertMailAddress(mailMessage.CC, "发送方邮件@126.com");//发送方邮件地址集,抄送不抄送给发送方126邮件将报错
mailMessage.From = from;
mailMessage.Subject = subject;
mailMessage.Body = body;
SmtpClient smtpClient = new SmtpClient(SmtpType);
smtpClient.Credentials = new NetworkCredential(MailFrom.Substring(0, MailFrom.IndexOf("@")), SmtpPassword);
if (SmtpType.ToUpper().IndexOf("QQ") == -1)//QQ无需绑定端口
{
int SmtpPort = Convert.ToInt32("25");
smtpClient.Port = SmtpPort;
//smtpClient.EnableSsl = false;
}
smtpClient.Send(mailMessage);
评论